package eitwitter.learning;

import java.util.Comparator;
import java.util.Map;

/**
 * Comparator servant à classer les valeurs d’une map par leur valeur (double)
 * @author AH & PJ
 *
 */
class ValueComparatorDouble implements Comparator<Integer> {

    Map<Integer, Double> base;
    boolean asc;
    public ValueComparatorDouble(Map<Integer, Double> base, boolean sens) {
        this.base = base;
        asc = sens;
    }

    // Note: this comparator imposes orderings that are inconsistent with equals.    
    public int compare(Integer a, Integer b) {
    	if(asc){
	        if (base.get(a) >= base.get(b)) {
	            return -1;
	        } else {
	            return 1;
	        } // returning 0 would merge keys
    	}
    	else{
    		 if (base.get(a) >= base.get(b)) {
 	            return 1;
 	        } else {
 	            return -1;
 	        } // returning 0 would merge keys
    	}
    }
}